package com.esm.controller;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.esm.model.User;
import com.esm.service.SelectSalaryService_zxk;
import com.esm.serviceimpl.SelectSalaryServiceImpl_zxk;
import com.esm.utils.PrintWriterUtil;

import net.sf.json.JSONObject;

/**
 * 获取个人实际薪水 Controller
 * @author 康少
 *
 * 2017年1月10日
 */
public class GetPersonSalaryController_zxk extends HttpServlet{
	SelectSalaryService_zxk salary = new SelectSalaryServiceImpl_zxk();
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doPost(req, resp);
	}
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		HttpSession session = req.getSession();
		String uname = ((User)session.getAttribute("currentUser")).getUname();
		String y = req.getParameter("year");
		String m = req.getParameter("month");
		//获得基本薪资
		float basicsalary = (float) session.getAttribute("basicsalary");
		int year = Integer.parseInt(y);
		int month = Integer.parseInt(m);
		//加班、出差、请假的薪资浮动值
		float realsalary = salary.getRealSalary(uname, year, month);
		//获得最终的薪资
		float actualSalary = basicsalary+realsalary;
		PrintWriter pw = resp.getWriter();
		JSONObject jo = new JSONObject();
		jo.put("actualSalary", actualSalary);
		PrintWriterUtil.flushJoAndClosePrintWriter(pw, jo);
	}
}
